var t = require("../../../../@babel/runtime/helpers/toConsumableArray");

require("../../../../@babel/runtime/helpers/Arrayincludes");

var e = getApp().globalData.base, a = getApp().globalData.api, s = getApp().globalData.tel;

Page({
    data: {
        hasSubmitSuccess: !1,
        rsList: [],
        reasonIndex: 0,
        checker: [],
        verify: {
            checkerId: null,
            checkStatus: null,
            tjzt: null,
            causeText: null,
            salesProofDTOList: [],
            reasonId: null,
            rescheduleDate: null,
            remark: null
        },
        medicalConditionIndex: 0,
        medicalCondition: [ {
            id: "S201",
            content: "未到检"
        }, {
            id: "S202",
            content: "已到检"
        } ],
        imgList: [],
        showImgList: []
    },
    onLoad: function(t) {
        console.log(t);
        var e = t.orderId, a = t.type, s = t.checkerId;
        this.getOrderData(e, a, s), wx.setNavigationBarTitle({
            title: this.getNavTitle(a)
        });
    },
    getNavTitle: function(t) {
        return 1 == t ? "申请退款" : 2 == t ? "申请改期" : "申请售后";
    },
    getOrderData: function(t, e, s) {
        var i = this, n = this;
        a.getPort("orderDetails", {
            rest: encodeURI(t)
        }, !0).then(function(a) {
            var r = !1, o = a.values.status;
            if ("9018" == o && 1 == e || "9002" == o && 1 == e || "9002" == o && 2 == e ? r = !0 : i.reminder("请联系客服处理售后～"), 
            r && "SUCCESS" == a.result) {
                var c = [];
                a.values.gdsItems[0].checkers.forEach(function(t, e) {
                    t.id == s && (c = [ t ]);
                }), n.setData({
                    checker: c,
                    orderId: t,
                    type: e,
                    hosData: a.values,
                    "verify.checkerId": a.values.gdsItems[0].checkers[0].id
                });
            }
        }, function(t) {}).then(function(t) {
            n.getResonData();
        });
    },
    getResonData: function() {
        var t = this;
        a.getPort("getAllAfterSalesApplyReason").then(function(e) {
            "SUCCESS" == e.result && t.data.hosData && (t.setData({
                reasonList: e.values
            }), t.checkRsList());
        }, function(t) {});
    },
    checkRsList: function() {
        if (1 == this.data.type) {
            if ("9002" == this.data.hosData.status) this.setData({
                "verify.checkStatus": null,
                rsList: null
            }); else if ("9018" == this.data.hosData.status) {
                var t = this.serachList("S204");
                this.setData({
                    "verify.checkStatus": "S204",
                    rsList: t
                });
            }
        } else if (2 == this.data.type) {
            var e = this.serachList("S203");
            this.setData({
                "verify.checkStatus": "S203",
                rsList: e
            });
        }
    },
    serachList: function(t) {
        for (var e = JSON.stringify(this.data.reasonList), a = JSON.parse(e), s = [], i = 0; i < a.length; i++) {
            a[i].reasonType.split(",").includes(t) && s.push(a[i]);
        }
        return s;
    },
    medicalConditionTap: function(t) {
        var e = this.serachList(this.data.medicalCondition[t.detail.value].id);
        this.setData({
            medicalConditionIndex: t.detail.value,
            reasonIndex: 0,
            "verify.tjzt": this.data.medicalCondition[t.detail.value].content,
            "verify.checkStatus": this.data.medicalCondition[t.detail.value].id,
            rsList: e
        });
    },
    tkReasonDisableTap: function() {
        this.reminder("请选择体检状态");
    },
    tkReasonTap: function(t) {
        this.setData({
            reasonIndex: t.detail.value,
            "verify.reasonId": this.data.rsList[t.detail.value].id,
            "verify.causeText": this.data.rsList[t.detail.value].content
        });
    },
    gqReasonTap: function(t) {
        this.setData({
            reasonIndex: t.detail.value,
            "verify.reasonId": this.data.rsList[t.detail.value].id,
            "verify.causeText": this.data.rsList[t.detail.value].content
        });
    },
    gqTimeTap: function() {
        this.selectComponent("#dataList").powerDrawer();
    },
    instructionsTap: function(t) {
        this.setData({
            "verify.remark": t.detail.value
        });
    },
    atTime: function(t) {
        this.setData({
            "verify.rescheduleDate": t.detail
        });
    },
    fileClick: function() {
        var a = this;
        wx.chooseImage({
            count: 1,
            sizeType: [ "original", "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(s) {
                console.log(s);
                var i = s.tempFilePaths, n = wx.getStorageSync("token");
                wx.showLoading(), wx.uploadFile({
                    url: e.port.upload,
                    filePath: i[0],
                    name: "file",
                    header: {
                        Authorization: "Bearer ".concat(n)
                    },
                    method: "post",
                    dataType: "json",
                    success: function(e) {
                        var s = JSON.parse(e.data);
                        if ("SUCCESS" == s.result) {
                            var n = a.data.imgList, r = a.data.showImgList;
                            r = [].concat(t(r), t(i)), n.push({
                                url: s.values.uri
                            }), a.setData({
                                imgList: n,
                                showImgList: r,
                                "verify.salesProofDTOList": n
                            });
                        } else a.reminder(s.message[0].message);
                    },
                    fail: function(t) {
                        a.reminder("网络超时");
                    },
                    complete: function(t) {
                        wx.hideLoading();
                    }
                });
            },
            fail: function() {},
            complete: function() {}
        });
    },
    deleteImg: function(t) {
        var e = t.currentTarget.dataset.index, a = this.data.imgList, s = this.data.showImgList;
        a.splice(e, 1), s.splice(e, 1), this.setData({
            imgList: a,
            showImgList: s,
            "verify.salesProofDTOList": a
        });
    },
    imgPreview: function(t) {
        var e = t.currentTarget.dataset.src;
        wx.previewImage({
            current: e,
            urls: this.data.showImgList
        });
    },
    phoneTap: function() {
        console.log("-->电话咨询"), wx.makePhoneCall({
            phoneNumber: s
        });
    },
    submitTap: function() {
        var t, e, a = this;
        1 == this.data.type ? "9018" == this.data.hosData.status ? (t = this.extend("reasonId", "remark", "salesProofDTOList"), 
        e = 0) : "9002" == this.data.hosData.status && (t = this.extend("checkStatus", "reasonId", "remark", "salesProofDTOList"), 
        e = 1) : 2 == this.data.type && "9002" == this.data.hosData.status && (t = this.extend("reasonId", "remark", "rescheduleDate", "checkerId"), 
        e = 2);
        var s = this.regular(t);
        if (s.type) {
            var i = this.getAlertData();
            wx.showModal({
                title: i.title,
                content: i.content,
                showCancel: !0,
                cancelText: "取消",
                cancelColor: "#000000",
                confirmText: "确定",
                confirmColor: "#04b9fc",
                success: function(t) {
                    t.confirm && a.requstSubmit(e, s.obj);
                },
                fail: function() {},
                complete: function() {}
            });
        } else this.reminder(s.msg);
    },
    requstSubmit: function(t, e) {
        var s = this, i = this;
        a.postPort([ "saveAfterSalesApplyForWaitAppointment", "saveAfterSalesApplyForAppointmented", "saveAfterSalesApplyReschedule" ][t], e).then(function(t) {
            "SUCCESS" == t.result && (i.setData({
                hasSubmitSuccess: !0
            }), setTimeout(function() {
                var t = getCurrentPages();
                t[t.length - 2].setData({
                    param: "newData"
                });
            }, 800));
        }, function(t) {
            "ERROR" == t.data.result && s.reminder(t.data.message[0].message);
        });
    },
    regular: function(t) {
        var e = {
            type: !0,
            msg: ""
        }, a = Object.prototype.toString;
        for (var s in t) {
            if ("[object String]" == a.call(t[s]) && (t[s] = t[s].replace(" ", "")), "checkStatus" == s && !t.checkStatus) return e.type = !1, 
            e.msg = "请选择体检状态", e;
            if ("reasonId" == s && !t.reasonId) return e.type = !1, e.msg = 1 == this.data.type ? "请选择退款原因" : "请选择改期原因", 
            e;
            if ("rescheduleDate" == s && !t.rescheduleDate) return e.type = !1, e.msg = "请选择改期日期", 
            e;
        }
        return e.obj = t, e;
    },
    getAlertData: function() {
        var t = {
            title: "",
            content: "",
            show: !1
        };
        return 1 == this.data.type ? t = {
            title: "确认申请退款？",
            content: "申请退款需要跟体检中心确认您是否到检并将收取10%服务费，退款需要3-7个工作日审核，确认退款吗？",
            show: !0
        } : 2 == this.data.type && (t = "9A22" == this.data.hosData.kind ? {
            title: "确认申请改期？",
            content: "",
            show: !0
        } : {
            title: "确认申请改期？",
            content: "每位客户拥有3次改期机会，无需支付任何费用的权益。3次后再改期，需扣除套餐实付金额的10%作为服务费。",
            show: !0
        }), t;
    },
    extend: function() {
        var t = {
            orderId: this.data.orderId
        }, e = this, a = [].slice.call(arguments);
        return a.forEach(function(a, s) {
            a in e.data.verify && (t[a] = e.data.verify[a]);
        }), t;
    },
    reminder: function(t) {
        wx.showToast({
            title: t,
            icon: "none",
            duration: 2e3,
            mask: !0
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {}
});